
<template>
<theme-box title="系统消息添加">
    <form class="form-inline" @submit.prevent v-el:form>
        <div class="box-body">
            <form-input title="消息标题" :required="true" name="msgTitle"></form-input>
            <form-input title="消息内容" :required="true" name="msgContent"></form-input>
            <form-select title="消息类型" :required="true" name="msgType" :options="mesgOptions"></form-select>
            <form-select title="消息种类" :required="true" name="msgType2" :options="msgOptions"></form-select>

        </div>
        <!-- /.box-body -->
        <div class="box-footer">
            <v-button type="reset" @click="reset">重置</v-button>
            <v-button type="submit" theme="primary" class="pull-right">确认</v-button>
        </div>
        <!-- /.box-footer -->
    </form>
</theme-box>
</template>

<script>
import 'plugins/jquery-validation';

var serialize = require('form-serialize');

export default {
    data: () => ({
        mesgOptions:[
        {key:"规则",value:"rule"},
        {key:"系统",value:"system"},
        {key:"活动",value:"act"}
        ],
        msgOptions:[
//            {key:"商户",value:"mcht"},
            {key:"系统",value:"system"},
            {key:"用户",value:"user"}
        ]
    }),
    methods: {
        reset() {
            $("label.error").remove();
            this.$els.form.reset()
        }
    },
    ready() {
        var self = this;
        $(this.$els.form).validate({
            submitHandler: async function() {
                var _data = serialize(this.currentForm, {
                    hash: true,
                    empty: true
                });
                 var result = await self.$post({
                    url: "/api/v1"+ projectName_Url +"/plat/msg/add",
                    data: _data,
                    method:"POST"
                })
                let data = {
                    title: "操作成功",
                    content: "是否进入系统消息列表查看?"
                }
                Midway.confirm(data).then(function () {
                    self.$route.router.go('/systemMessage/list');
                })
                self.reset()
            },

            errorPlacement: function(error, element) {
                if (element.attr("name") == "file") {
                    error.insertAfter(".file-item");
                } else {
                    error.insertAfter(element)
                }
            },
            rules: {
               msgTitle: {
                    required: true,
                    stringMaxLength:32
                },
                msgContent:{
                    required: true,
                    maxlength:128
                },
                msgType:{
                    required: true,
                    maxlength:11
                },
            },
        });
    }
}
</script>
